package com.school.dcc.response;

import java.util.HashMap;
import java.util.Map;

public class CommonResponse{
    private Boolean success;
    private int code;
    private String message;
    private Map<String, Object> data = new HashMap<String, Object>();

    private CommonResponse(){}

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(ResultCode code) {
        this.code = code.code();
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(ResultCode message) {
        this.message = message.message();
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public static CommonResponse ok(){
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setSuccess(true);
        commonResponse.setCode(ResultCode.HTTP_SUCCESS);
        commonResponse.setMessage(ResultCode.HTTP_SUCCESS);
        return commonResponse;
    }

    public static CommonResponse error(){
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setSuccess(false);
        commonResponse.setCode(ResultCode.HTTP_FAIL);
        commonResponse.setMessage(ResultCode.HTTP_FAIL);
        return commonResponse;
    }

    public CommonResponse success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public CommonResponse message(ResultCode message){
        this.setMessage(message);
        return this;
    }

    public CommonResponse code(ResultCode code){
        this.setCode(code);
        return this;
    }

    public CommonResponse data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public CommonResponse data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

}
